//
//  CRMTableViewCell.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/8/1.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "CRMTableViewCell.h"

@interface CRMTableViewCell (){    //
    
    NSIndexPath *tempIndexPath;
    NSDictionary *tempDic;
    
    UIView *viewBg;
    UILabel *lblTitle;
    UILabel *lblContent;
    UIImageView *imageIcon;
    UILabel *lblDate;
    
    UIImageView *imageRedTip;
//    UIView *viewLine;
}

@end
@implementation CRMTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        viewBg=[[UIView alloc]initWithFrame:CGRectMake(10, 5, kScreenWidth-20, 50)];
        [viewBg setBackgroundColor:RGBCOLOR(255, 255, 255)];
        [self addSubview:viewBg];
        [[Utility Share] viewLayerRound:viewBg borderWidth:1 cornerRadius:4 borderColor:[UIColor clearColor]];
        
        lblTitle=[RHMethods labelWithFrame:CGRectMake(10, 10, W(viewBg)-30, 0) font:fontTitle color:rgbTitleColor text:@""];
        [viewBg addSubview:lblTitle];
        lblTitle.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        
        imageRedTip=[RHMethods imageviewWithFrame:CGRectMake(W(viewBg)-17, 7, 7, 7) defaultimage:@"redTip070116" contentMode:UIViewContentModeScaleAspectFit];
        [viewBg addSubview:imageRedTip];
        imageRedTip.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
        
        lblContent=[RHMethods labelWithFrame:CGRectMake(10, 10, W(viewBg)-20, 20) font:fontTxtContent color:rgbTxtDeepGray text:@""];
        [viewBg addSubview:lblContent];
        lblContent.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        
        imageIcon=[RHMethods imageviewWithFrame:CGRectMake(10, 10, 8, 20) defaultimage:@"timeicon" contentMode:UIViewContentModeScaleAspectFit];
        [viewBg addSubview:imageIcon];
        
        lblDate=[RHMethods labelWithFrame:CGRectMake(23, 10, W(viewBg)-33, 20) font:fontSmallTitle color:rgbTxtGray text:@""];
        [viewBg addSubview:lblDate];
        
//        viewLine=[RHMethods lineViewWithFrame:CGRectMake(0, 0, kScreenWidth, 0.5)];
//        [self addSubview:viewLine];
//        viewLine.hidden=YES;
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}

//内容更新
-(NSInteger)setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath type:(NSString *)strType{
    tempIndexPath=indexPath;
    tempDic=dic;
    
    NSString *strTitle=[NSString stringWithFormat:@"%@(%@)",[dic valueForJSONStrKey:@"name"],[dic valueForJSONStrKey:@"companyname"]];
    if ([strType isEqualToString:@"crm"]) {
        strTitle=[dic valueForJSONStrKey:@"name"];
    }
    lblTitle.text=strTitle;
    
    imageRedTip.hidden=YES;//![[dic valueForJSONStrKey:@"isread"] isEqualToString:@"0"];
    
    lblContent.text=[NSString stringWithFormat:@"%@ | %@ | %@",[dic valueForJSONStrKey:@"mobile"],[dic valueForJSONStrKey:@"wechat"],[dic valueForJSONStrKey:@"email"]];//,@"中外合资",@"2014年",@"2000万人民币",@"ZhangSan"
    
    
    lblDate.text=[dic valueForJSONStrKey:@"ctime"];//@"2017-03-23 12:12";//[[Utility Share] timeToTimestamp:[dic valueForJSONStrKey:@"ctime"]];//
    
    float fh=[lblTitle sizeThatFits:CGSizeMake(kScreenWidth-50, MAXFLOAT)].height;
    lblTitle.frameHeight=fh>20?40:20;
    lblContent.frameY=YH(lblTitle);
    float fhT=[lblContent sizeThatFits:CGSizeMake(W(lblContent), MAXFLOAT)].height;
    lblContent.frameHeight=fhT;
    
    lblDate.frameY=YH(lblContent);
    imageIcon.frameY=YH(lblContent);
    
           //55
    viewBg.frameHeight=H(lblTitle)+55;
    
    return YH(viewBg)+5;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
